package ThreadPoolDemo.lockDemo;

import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.CountDownLatch;

/**
 * Created by zzy on 2018/4/8.
 */
public class waitNotify {

   public volatile static int a=0;
   public static Random rand = new Random();
    public static void main(String[] args) throws InterruptedException {
        waitNotify waitNotify=new waitNotify();
        waitNotify.runTest();
    }

   public void runTest() throws InterruptedException {
       for(int i=0;i<10;i++) {
           final int num = i;
           synchronized ("asd") {
               Thread thread = new Thread(new Runnable() {
                   @Override
                   public void run() {
                       a = num;
                       try {
                           Thread.sleep(rand.nextInt(100));
                       } catch (InterruptedException e) {
                           e.printStackTrace();
                       }
                       System.out.println("第" + num + "次：a=" + a);
                   }
               });
               thread.start();
              // thread.join();
           }
       }
       System.out.println(a);
       CountDownLatch countDownLatch=new CountDownLatch(10);
       countDownLatch.countDown();
       countDownLatch.getCount();
       countDownLatch.await();
   }
}
